﻿using Moven.Controls;
using Xamarin.Forms;

namespace Moven
{
	public static class ViewExtensions
	{
		public static void UpdateEnableDisable(this ExtendedToolbarItem button)
		{
			((Command)button.Command).ChangeCanExecute();
#if __ANDROID__
			button.IsEnabled = button.Command.CanExecute(null);
#endif
		}

		public static T GetParentViewOfType<T>(this Element view) where T: Element
		{
			var parent = view.Parent;
			while (parent != null && parent.Parent != null && !(parent is T))
			{
				parent = parent.Parent;
			}

			return (T)parent;
		}
	}
}
